$(function() {

    listClass(1);

    // 课程加载
    function listClass(pageNo) {
        var params = {'name':$('#search').val()};
        params = JSON.stringify(params);
        loadMobilePathData({
            url: baseloaction + '/mobile/class/search/ajax/result',
            contextId: 'class-list',
            pageNo: pageNo,
            pageCall: listClass,
            params: params,
            callback: function (pageNo) {
            }
        });
    }

    $('body')
        .on('click', 'li.item-content', function (e) { // 班级详情
            var target = e.target;
            if (target.dataset['join']) {
                joinClass(target.dataset['join']);
            } else {
                var classId = $(this).data('class');
                window.location = baseloaction + '/mobile/class/info?classId=' + classId;
            }
        });

    // 加入班级
    function joinClass(classId) {
        $.ajax({
            url: baseloaction + '/mobile/uc/class/user/joined',
            data: {'classId': classId},
            dataType: 'json',
            success: function (response) {
                $.toast(response.message);
            }
        })
    }

});